package com.example.schedule.job;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HelloJobConfig {
    @Bean
    public JobDetail helloJobDetail() {
        return JobBuilder
                .newJob(HelloJob.class)
                .withIdentity("DateTimeJob")
                .usingJobData("msg", "hello job")
                .usingJobData("name", "test hello job")
                .storeDurably() //即使没有trigger关联，也不需要删除该jobDetail
                .build();
    }

    @Bean
    public Trigger helloJobTrigger(){
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0/2 * * * * ?");
        return TriggerBuilder
                .newTrigger()
                .forJob(helloJobDetail())
                .withIdentity("quartzTaskService")
                .withSchedule(cronScheduleBuilder)
                .build();
    }
}
